// pages/auth/auth.js
import {
  request
} from '../../request/request'
import {
  login
} from '../../utils/asyncWX'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  async handleGetUserInfo(e) {
    try {
      // console.log(e);
      const {
        encryptedData,
        rawData,
        signature,
        iv
      } = e.detail
      const {
        code
      } = await login()
      // console.log(code);
      const token = await request({
        url: '/users/wxlogin',
        data: {
          encryptedData,
          rawData,
          signature,
          iv,
          code
        },
        method: 'POST'
      })
      // console.log(token);
      wx.setStorageSync('token', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo');
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error);
    }
  }
})